package com.flyoil.petromp.adapter.adapter_order;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flyoil.petromp.R;
import com.flyoil.petromp.base.MyBaseAdapter;
import com.flyoil.petromp.entity.entity_order.MapListEntity;
import com.flyoil.petromp.entity.entity_order.OrderGoodsEntity;
import com.flyoil.petromp.utils.OrderUtl.OrderMessageUtil;

import java.util.List;

/**
 * Created by Administrator on 2017/10/27.
 * 工单详情物品列表item的适配器
 */

public class ItemOrderMessageGoodsAdapter extends MyBaseAdapter<OrderGoodsEntity> {
    private OrderMessageUtil orderMessageUtil;

    public ItemOrderMessageGoodsAdapter(Context context) {
        super(context);
        orderMessageUtil = new OrderMessageUtil(context);
    }


    @Override
    public View setView(int position, View convertView, ViewGroup parent) {
        ViewHoder viewHoder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_order_message_goods_layout, null);
            viewHoder = new ViewHoder(convertView);
            convertView.setTag(viewHoder);
        } else {
            viewHoder = (ViewHoder) convertView.getTag();
            viewHoder.line_goods.removeAllViews();
        }
        OrderGoodsEntity entity = (OrderGoodsEntity) getItem(position);
        List<MapListEntity> mapListEntities = entity.getMapListEntities();
        orderMessageUtil.init_text_map_view(mapListEntities, viewHoder.line_goods);
        return convertView;
    }

    private class ViewHoder {
        private LinearLayout line_goods;

        public ViewHoder(View view) {
            this.line_goods = view.findViewById(R.id.line_item_order_message_goods_layout);
        }
    }
}
